<template>
	<view id="action">
		<my-header :title="title" :back="true"></my-header>
		<view style="margin-top: 60px;">		
			<view class="" v-for="(item, index) in listData">
				<uni-card v-if="item.type == 2"  @tap="itemDetail(item)">
					<image class="hotImg" src="../../static/hot.png" mode="widthFix" v-if="timeSub(item.releaseTime) <= 3"></image>
					<view class="titleList">
						<image :src="index % 2 == 0 ? '../../static/checked1.png' : '../../static/checked2.png'" mode="widthFix"></image>
						{{item.title}}
					</view>	
					<view class="footTxt">
						<view class="">
							<view class="" v-if="item.deadline">
								{{timeSub(item.deadline) ? '倒计时:' + timeSub(item.deadline) + '天' : '已结束'}}
							</view>								
						</view>
						<view class="">发布时间：{{item.releaseTime.split(' ')[0]}}</view>
					</view>
				</uni-card>
				<uni-link v-else :href="item.link" showUnderLine="false">
					<uni-card >
						<image class="hotImg" src="../../static/hot.png" mode="widthFix" v-if="timeSub(item.releaseTime) <= 3"></image>						
						<view class="titleList">
							<image :src="index % 2 == 0 ? '../../static/checked1.png' : '../../static/checked2.png'" mode="widthFix"></image>
							{{item.title}}
						</view>	
						<view class="footTxt">
							<view class="">
								<view class="" v-if="item.deadline">
									{{timeSub(item.deadline)<0 ? '倒计时:' + Math.abs(timeSub(item.deadline)) + '天' : '已结束'}}
								</view>								
							</view>
							<view class="">发布时间：{{item.releaseTime.split(' ')[0]}}</view>
						</view>
					</uni-card>
				</uni-link>

			</view>
		</view>
		<uni-pagination :total="total" @change="changePage" style="padding: 0 10px;" />
	</view>
</template>

<script>
	import MyHeader from '@/components/header.vue'
	export default {
		components: {
			MyHeader,
		},
		data() {
			return {
				title: '热点资讯',
				total: 0,
				current: 1,
				listData: [
					{
						content: "这是最新消息内容测试3",
						releaseTime: "2024-06-04 15:42:35",
						title: "权威信息转载丨重磅！关系保交房、个人房贷，最新政策要点汇总",
					},
					
				],
				query: {
					page: 1,
				},
			}
		},
		created() {
			this.init()
		},
		methods: {
			timeSub(date) {
				if(!date) return 0
				let now = new Date().toLocaleDateString()
				let time = new Date(date.split(' ')[0]).toLocaleDateString()
				let sub = (new Date(now).getTime() - new Date(time).getTime()) / (24 * 60 * 60 * 1000)
				console.log(now, time, sub)
				return sub
			},
			init() {
				uni.showLoading({
					title: '加载中'
				});
				uni.request({
					url: '/sf_enterprise_service/business/anonnews/queryPage',
					method: 'GET',
					data: this.query,
					success: (res) => {		
						console.log(res, 'res??')
						if(res.data.data.list.length) {	
							this.listData = res.data.data.list
							this.total = res.data.data.totalCount							
							console.log(this.listData)
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							})
						}
					},
					complete: () => {							
						uni.hideLoading();
					}
				})
			},
			changePage(e) {
				console.log(e)
				// this.current = e.current
				this.query.page = e.current
				this.init()
			},
			itemDetail(item) {
				uni.navigateTo({
					url: '/pages/activity/activityDetail?item=' + JSON.stringify(item)
				})			
			}
		}
	}
</script>

<style scoped>
.hotImg {
	width: 20px;
	position: absolute;
	right: 0;
	top: 0px;
	z-index: 2;
}
.titleList {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	padding: 10px 0;
	font-weight: bold;
}
.titleList image {
	width: 16px;
	top: 3px;
	margin-right: 5px;
}
.footTxt {
	font-size: 12px;
	color: #a6a6a6;
	display: flex;
	justify-content: space-between;
}
</style>

